package com.example.service;

import com.example.common.util.OkHttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.concurrent.CompletableFuture;

@Slf4j
@Component
public class AsyncTaskService {


    public CompletableFuture<String> doTaskBlock(String url, String id) throws Exception {
        String sync = OkHttpUtils.builder().url(url)
                .addParam("id", id)
                .get()
                .sync();
        return CompletableFuture.completedFuture(sync);
    }

    @Async("taskExecutor")
    public CompletableFuture<String> doTaskOneAsync(String url, String id) throws Exception {
        String sync = OkHttpUtils.builder().url(url)
                .addParam("id", id)
                .get()
                .sync();
        return CompletableFuture.completedFuture(sync);
    }


}